package com.bosssoft.setp.handler;


import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.TagsFetchHandler;
import xyz.erupt.jpa.dao.EruptDao;;

import javax.annotation.Resource;
import java.util.List;

/**
 * 标签选择器
 *
 * @author clt
 */
@Service
public class TagsFetchHandlerImpl implements TagsFetchHandler {
    @Resource
    private EruptDao eruptDao;

    private final String sql = "select id from e_dict where name = '?'";

    /**
     * 选择标签
     * @param params
     * @return
     */
    @Override
    public List<String> fetchTags(String[] params) {
        Long dictId = eruptDao.getJdbcTemplate().queryForObject(sql.replace("?", params[0]), Long.class);
        List<String> dictItems = eruptDao.getJdbcTemplate().query("select name from e_dict_item where erupt_dict_id = ?", new Object[]{dictId}, (rs, rowNum) -> {
            return rs.getString("name");
        });
        return dictItems;
    }
}